/*
 * @Author: biankai
 * @Date: 2021-04-19 18:47:04
 * @LastEditTime: 2021-11-05 17:28:26
 * @LastEditors: biankai
 * @FilePath: /gitee/devops_service/src/controllers/kubernetes/Deployment.controller.ts
 */
import { Controller, Inject, Get, Query, Param, Post, Put, Delete, Body } from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import * as kubernetes from '@kubernetes/client-node';
import { DeploymentService } from '../../services/kubernetes/deployment.service';

@ApiTags('K8s-部署对象')
@Controller('kubernetes/deployment')
export class DeploymentController {
    constructor(@Inject(DeploymentService) private readonly deploymentService: DeploymentService) {
    }


    @ApiOperation({ summary: '获取指定命名空间下的部署节点', description: '说明 : 调用此接口,可获取指定命名空间下的部署节点' })
    @ApiCreatedResponse({
        description: 'The record has been successfully created.',
        type: kubernetes.V1Namespace
    })
    @Get(':namespaceName')
    async listK8sNamespace(@Param('namespaceName') namespaceName,) {
        return await this.deploymentService.listNamespacedDeployment(namespaceName)
    }

    @ApiOperation({ summary: '获取指定命名空间下的单个部署节点', description: '说明 : 调用此接口,可获取指定命名空间下的单个部署节点' })
    @Get(':namespaceName/:name')
    async singleK8sNamespace(@Param('namespaceName') namespaceName, @Param('name') name) {
        return await this.deploymentService.readNamespacedDeployment(namespaceName, name)
    }

    @ApiOperation({ summary: '新增指定命名空间下的单个部署节点', description: '说明 : 调用此接口,可新增指定命名空间下的单个部署节点' })
    @Post(':namespaceName')
    async createK8sNamespace(@Param('namespaceName') namespaceName, @Body() deploymentDto) {
        return await this.deploymentService.createNamespacedDeployment(namespaceName, deploymentDto)
    }

    @ApiOperation({ summary: '修改指定命名空间下的单个部署节点', description: '说明 : 调用此接口,可修改指定命名空间下的单个部署节点' })
    @Put(':namespaceName/:name')
    async replaceK8sNamespace(@Param('namespaceName') namespaceName, @Param('name') name, @Body() deploymentDto) {
        return await this.deploymentService.replaceNamespacedDeployment(namespaceName, name, deploymentDto)
    }
    @ApiOperation({ summary: '删除指定命名空间下的单个部署节点', description: '说明 : 调用此接口,可删除指定命名空间下的单个部署节点' })
    @Delete(':namespaceName/:name')
    async deleteK8sNamespace(@Param('namespaceName') namespaceName, @Param('name') name) {
        return await this.deploymentService.deleteNamespacedDeployment(namespaceName, name)
    }


}